#include<bits/stdc++.h>
#define ll long long
ll A[100010],C[100010];
ll co[100010];
int n,i=1;
//waht i written?
void f(int k){
    if(i==10)return;//?
    for(int i=1;i<=n;i++){i++;
        if(co[k+i]==co[k]&&A[k+i]!=A[k])A[k+i]=-A[k];
        if(A[k]==A[i]){
            co[k]=co[i];
            C[k]=A[k];
            f(k+1);
            co[k]=-co[i];
        }
    }
}

using namespace std;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
int t;
scanf("%d",&t);
while(t--){

    memset(A,0,sizeof(A));
    memset(C,0,sizeof(C));
    memset(co,1,sizeof(co));
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&A[i]);
    }
    reverse(A+1,A+n+1);
    int ans=0;
    for(int i=1;i<=n;i++){
        ans+=C[i];
    }
    cout<<ans<<endl;




}return 0;}
